import request from '@/utils/request'

export function getList(type, params) {
  let url = ''
  switch (type) {
    case 'getSteam':
      url = 'getSteam'
      break
    case 'getSummarySteam':
      url = 'getSummarySteam'
      break
    case 'getTransaction':
      url = 'getTransaction'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'get',
      params
    })
      .then(res => {
        resolve(res)
      })
      // eslint-disable-next-line handle-callback-err
      .catch(error => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve(data)
      })
  })
}

export function addOne(type, data) {
  let url = ''
  switch (type) {
    case 'getSteamAdd':
      url = 'getSteamAdd'
      break
    case 'getSteamAddList':
      url = 'getSteamAddList'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function updateOne(type, data) {
  let url = ''
  switch (type) {
    case 'getSteamUpdate':
      url = 'getSteamUpdate'
      break
    case 'getSteamBatchUpdate':
      url = 'getSteamBatchUpdate'
      break
    case 'getSteamCheck':
      url = 'getSteamCheck'
      break
    case 'getSyncSteam':
      url = 'getSyncSteam'
      break
    case 'getSyncDeal':
      url = 'getSyncDeal'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function deleteOne(type, data) {
  let url = ''
  switch (type) {
    case 'getSteamDelete':
      url = 'getSteamDelete'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}
